package com.java.grammer.equal.exer3;

import java.util.Objects;

/**
 * @author luzhikun
 * @date 2020/12/7- 8:19
 */
public abstract class Person {
    String name;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Person person = (Person) o;
        return age == person.age &&
                name.equals(person.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    int age;

    public Person() {

    }

    public Person(String name, int age) {
        this.age = age;
        this.name = name;

    }

    public abstract void eat();
    //手写的
    /*
    public boolean equals(Person person){
        if (this==person){
            return true;
        }
        if (person instanceof Student){
            Student student=(Student)person;
            if (this.age==student.age && this.name.equals(student.name)){
                return true;
            }else
                return false;
        }
        return false;
    }
     */
}
